import requests
import sqlite3
from lxml import etree

res = requests.get("https://www.xiaoshuopu.com/")
content = res.text
tree = etree.HTML(content)
right_data = tree.cssselect(".ultop li a")
right_datas = []
for ri in right_data:
    right_datas.append(ri.text)

print(right_datas)


recommend_index = list(zip(right_datas[:17]))
print(recommend_index)

latest_data = list(zip(right_datas[17:]))
print(latest_data)



con = sqlite3.connect("../mysite/db.sqlite3")
cur = con.cursor()
cur.executemany('insert into main_recommendindex (name) values (?)', recommend_index)
con.commit()
cur.close()
con.close()


con = sqlite3.connect("../mysite/db.sqlite3")
cur = con.cursor()
cur.executemany('insert into main_latestindex (name) values (?)', latest_data)
con.commit()
cur.close()
con.close()